﻿@using VocaDb.Web.Helpers
@inherits VocaDb.Web.Code.VocaDbPage<VocaDb.Model.Domain.Security.IPRule[]>

@{
    PageProperties.Title = "Manage blocked IPs";
    ViewBag.Parents = new[] { 
		Html.ActionLink("Manage", "Index"), 
	};    
}

<form id="manageRules" data-bind="submit: save, show" class="js-cloak">
    
	@Helpers.SaveBtn()
	
	<button class="btn" data-bind="click: deleteOldRules">Delete rules older than 1 year</button>
    
	<div class="editor-label">
		<label>
			New address
		</label>
	</div>
	<div class="editor-field">
		<input type="text" maxlength="40" data-bind="textInput: newAddress" />
		<a href="#" class="textLink addLink" data-bind="click: add">@ViewRes.SharedStrings.Add</a>
	</div>

	<table>
		<thead>
			<tr>
				<th>Address</th>
				<th>Notes</th>
				<th>Created</th>			    
				<th></th>
			</tr>
		</thead>
		<tbody data-bind="foreach: rules">
			<tr>
				<td>{{address}}</td>
				<td>
					<input type="text" data-bind="value: notes" />
				</td>
				<td>{{ created | formatDate: 'L LT' }}</td>
				<td><a href="#" class="textLink deleteLink" data-bind="click: $parent.remove">@ViewRes.SharedStrings.Remove</a></td>
			</tr>			
		</tbody>
	</table>
    
	@Helpers.SaveBtn()

</form>

<div data-bind="if: bannedIPs().length > 0, show" class="js-cloak">
	<h2>Automatically banned IPs</h2>
	<ul data-bind="foreach: bannedIPs">
		<li>
			@{ Html.RenderPartial("KnockoutPartials/_IPManage"); }
		</li>
	</ul>
</div>

@section BodyScripts {
	<script type="text/javascript" src="@Url.Content("~/Scripts/moment-with-locales.js")"></script>
	<script type="text/javascript" src="@Url.Content("~/Scripts/KnockoutExtensions/FormatDateFilter.js")"></script>
	<script type="text/javascript" src="@Url.Content("~/Scripts/ViewModels/Admin/ManageIPRulesViewModel.js")"></script>
	<script type="text/javascript">
	$(function () {

    	moment.locale('@Culture');
		ko.punches.enableAll();

    	var rules = @Html.Raw(JsonHelpers.Serialize(Model, true, true));
		var urlMapper = new vdb.UrlMapper('@RootPath');
		var repo = new vdb.repositories.AdminRepository(urlMapper);

    	var viewModel = new vdb.viewModels.ManageIPRulesViewModel(rules, repo);
    	ko.applyBindings(viewModel);

	});
	</script>
}